package framework.office.apache.poi.xls;
import java.io.FileOutputStream;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.util.CellRangeAddress;

import framework.office.apache.poi.style.XlsStyle;
public class Input {
	public static String path = "C:/Users/K/Desktop/1/test.xls";
	public static void main(String[] args) throws Exception {
		createXls1();
	}
	static void createXls() throws Exception {
		HSSFWorkbook book = new HSSFWorkbook();
		FileOutputStream out = new FileOutputStream(path);
		book.write(out);
		out.flush();
		out.close();
	}
	static void createXls1() throws Exception {
		HSSFWorkbook book = new HSSFWorkbook();
		// book.createSheet();
		HSSFSheet sheet = book.createSheet();
		// 合并单元格
		// 合并后取左上角的值
		sheet.addMergedRegion(new CellRangeAddress(5, 10, 0, 3));
		// 创建行
		sheet.createRow(0);
		// 设置列宽
		// sheet.setColumnWidth(0, 30000);
		HSSFRow row = sheet.getRow(0);
		// 设置行高
		// row.setHeight((short) 3000);
		row.createCell(0);
		// 创建cell
		HSSFCell cell = row.getCell(0);
		cell.setCellValue(1234832432);
		HSSFCellStyle style = XlsStyle.getStyle(book.createCellStyle());
		System.out.println(style.getDataFormatString());
		cell.setCellStyle(style);
		cell.setCellFormula("e2");
		FileOutputStream out = new FileOutputStream(path);
		book.write(out);
		out.flush();
		out.close();
	}
	static void m1() throws Exception {
		HSSFWorkbook wb = new HSSFWorkbook();
		HSSFSheet sheet = wb.createSheet();
		HSSFRow row = sheet.createRow(0);
		row.setHeight((short) 250);
		sheet.setColumnWidth((short) 0, (short) 250);
		FileOutputStream fileOut = new FileOutputStream(path);
		wb.write(fileOut);
		fileOut.close();
	}
}
